var DAO = require('./DAO')
var userDAO = {
    getUsersDetail: function (phone, callback) {
        DAO('select * from userInfos where phone=?', [phone], function (err, results) {
            if (err) {
                callback(err, null)
            } else {
                callback(null, results)
            }
        })
    },
    register: function (user, callback) {
        DAO('insert into userInfos(userName,password,phone) values(?,?,?)', [user.phone, user.psw, user.phone], function (err, results) {
            if (err) {
                callback(err, null)
            } else {
                callback(null, results)
            }
        })


    },
    login: function (phone, callback) {
        DAO('select password from userInfos where phone=?', [phone], function (err, results) {
            if (err) {
                callback(err, null)
            } else {
                callback(null, results)
            }
        })
    },
    msgCheck: function (tel,callback) {
        DAO('select * from userInfos where phone=?', [tel], function (err, results) { 
            if (err) {
                callback(err, null)
            } else {
                callback(null, results)
            }
        })
    },
    changeUserInfos: function (user, callback) {
        DAO('update userInfos set userName=?,phone=?,address=?,sex=?,Email=?,birthday=? where userId=?', [user.userName,user.phone,user.address,user.sex,user.Email,user.birthday,user.userId], function (err, results) {
            if (err) {
                callback(err, null)
            } else {
                callback(null, results)
            }
        })
    },
    changePsw: function (user, callback) {
        DAO('update userInfos set password=? where phone=?', [user.newPsw,user.phone], function (err, results) {
            if (err) {
                callback(err, null)
            } else {
                callback(null, results)
            }
        })
    },
    uploadPic: function (user, callback) {
        DAO('update userInfos set headPic=? where userId=?', [user.headPic,user.userId], function (err, results) {
            if (err) {
                callback(err, null)
            } else {
                callback(null, results)
            }
        })
    }


}
module.exports = userDAO